package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.model.BalanceHistoryModel;
import com.keyancompany.zhongbaopingtai.model.SearchRecordModel;
import com.keyancompany.zhongbaopingtai.weight.CircleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by firefox on 2016/6/15.
 */
public class CircleThemeAdapter extends ListAdapter<SearchRecordModel> {

    private String type;
    private View.OnClickListener clickListener;

    public void setType(String type , View.OnClickListener listener) {
        this.type = type;
        this.clickListener = listener;
    }

    public CircleThemeAdapter(Context ctx) {
        super(ctx);
    }

    @Override
    public int getContentViewId() {
        return R.layout.item_circle_theme;
    }

    @Override
    public HolderView getHoldView(int position, View contentView, ViewGroup parent) {
        CircleThemeHolder hold = new CircleThemeHolder();
        hold.title = (TextView) contentView.findViewById(R.id.user_name);
        hold.time = (TextView) contentView.findViewById(R.id.time);
        hold.goTheme = (TextView) contentView.findViewById(R.id.go_theme);
        hold.content = (TextView) contentView.findViewById(R.id.content);
        hold.avator = (CircleImageView) contentView.findViewById(R.id.user_avatar);
        return hold;
    }

    @Override
    public void setItemView(final int position, HolderView contentView, final SearchRecordModel item) {
        CircleThemeHolder hold = (CircleThemeHolder) contentView;
        if (!TextUtils.isEmpty(type) && type.equals("friends")) {
            hold.goTheme.setText("更多评论");
        } else {
            hold.goTheme.setText("进入话题");
        }
        hold.content.setText(item.getMsg());
        hold.time.setText(item.getCreatetime());
        hold.title.setText(item.getUsername());
        hold.goTheme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(clickListener !=null){
                    view.setTag(item);
                    clickListener.onClick(view);
                }
            }
        });
        ImageLoader.getInstance().displayImage(item.getHeadpic(), hold.avator);
    }

    class CircleThemeHolder extends HolderView {

        TextView title;

        TextView content;

        TextView time;

        TextView goTheme;

        CircleImageView avator;

    }

}
